#ifndef OPENGLFRAMEBUFFER_H
#define OPENGLFRAMEBUFFER_H

#include "Renderer/framebuffer.h"

namespace CC {

	class OpenGLFramebuffer : public Framebuffer
	{
	public:
		OpenGLFramebuffer(const FramebufferSpecification& spec);
		virtual ~OpenGLFramebuffer();

		void Invalidate();

		virtual void Bind() override;
		virtual void Unbind() override;

		virtual void Resize(uint32_t width, uint32_t height) override;
		virtual int ReadPixel(uint32_t attachmentIndex, int x, int y) override;

		virtual void ClearAttachment(uint32_t attachmentIndex, int value) override;

		virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const override { 
            if(index >= m_ColorAttachments.size()) return 0;
            return m_ColorAttachments[index]; 
            }

		virtual const FramebufferSpecification& GetSpecification() const override { return m_Specification; }

		uint32_t GetDepthAttachmentID() { return m_DepthAttachment; }
		Texture2D *GetDepthAttachmentTexture2D() { return m_DepthAttachmentTexture; }
		Texture2D *GetColor0AttachmentTexture2D() { return m_Color0AttachmentTexture; }

	private:
		uint32_t m_RendererID = 0;
		FramebufferSpecification m_Specification;

		std::vector<FramebufferTextureSpecification> m_ColorAttachmentSpecifications;
		FramebufferTextureSpecification m_DepthAttachmentSpecification = FramebufferTextureFormat::None;

		std::vector<uint32_t> m_ColorAttachments;
		uint32_t m_DepthAttachment = 0;
		Texture2D *m_DepthAttachmentTexture;
		Texture2D *m_Color0AttachmentTexture;
	};

}

#endif